from odoo import api, fields, models


class ProductTemplate(models.Model):
    _inherit = 'product.template'

    requisition_id = fields.Many2one('purchase.requisition', 'Purchase Requisition')

    @api.constrains('requisition_id')
    def _check_requisition_id(self):
        for rec in self:
            if rec.requisition_id:
                rec.requisition_id.state = 'done'
                # 关联采购申请单
                # rec.requisition_id.write({'product_tmpl_ids': [(4, rec.id)]})
